package com.springboot.cloud.demos.feign.service;

import com.springboot.cloud.common.core.constant.Constant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

import static com.springboot.cloud.common.core.constant.Constant.THIRTY_MIN;

@Service
public class RedisServiceImpl implements RedisService {

    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public String getRedisValue(String key) {
        return stringRedisTemplate.opsForValue().get(key);
    }

    @Override
    public void setRedisValue(String key, String value) {
        stringRedisTemplate.opsForValue().set(key, value, THIRTY_MIN, TimeUnit.SECONDS);
    }

    @Override
    public void setRedisValue(String key, String value, Long expire)  {
        stringRedisTemplate.opsForValue().set(key, value, expire, TimeUnit.SECONDS);
    }
}
